package com.samphanie.admin.modules.sys.controller;

import com.samphanie.admin.modules.sys.domain.vo.UserProfileVo;
import com.samphanie.admin.modules.sys.service.ISysUserService;
import com.samphanie.common.enums.ResultCode;
import com.samphanie.common.execetion.ApiException;
import com.samphanie.common.utils.ApiResponse;
import com.samphanie.mbg.model.sys.SysUser;
import com.samphanie.security.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZSY
 * @date 2021/11/9 9:20
 */
@Slf4j
@Api(tags = "user")
@RestController
@RequestMapping("/api/v1/user")
@RequiredArgsConstructor
public class UserController {

    private final ISysUserService userService;

    @ApiOperation(value = "当前登录用户详情")
    @GetMapping("/info")
    public ApiResponse<UserProfileVo> queryCurrentUser() {
        log.info("获取当前登陆的用户信息 begin");
        // 用户基本信息
        String username = SecurityUtil.getCurrentUsername();
        SysUser user = userService.findUserByUsername(username)
                .orElseThrow(() -> new ApiException(ResultCode.USER_ERROR_A0201));

        UserProfileVo userVo = UserProfileVo.fromUserProfileVo.apply(user);
        // 用户按钮权限信息
        // List<String> perms = permissionService.listBtnPermByRoles(roles);
        // userVo.setPerms(perms);

        return ApiResponse.success(userVo);
    }

}
